//
//  UIButton + Category.swift
//
//  Created by mac1 on 16/11/26.
//  Copyright © 2016年 万利. All rights reserved.
//

import UIKit
extension UIButton
{
    class func createButton(title: String, titleColor: UIColor, font:CGFloat, imageName: String, backgroundImageName: String, target: AnyObject?, action: Selector) -> UIButton{
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), for: UIControlState())
        btn.setTitle(title, for: UIControlState())
        btn.setTitleColor(titleColor, for: UIControlState())
        btn.titleLabel?.font = UIFont.systemFont(ofSize: font)
        btn.setBackgroundImage(UIImage(named: backgroundImageName), for: UIControlState())
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        return btn
    }
    
    convenience init(title: String, titleColor: UIColor, font:CGFloat, imageName: String, backgroundImageName: String) {
        self.init()
        setImage(UIImage(named: imageName), for: UIControlState())
        setTitle(title, for: UIControlState())
        setTitleColor(titleColor, for: UIControlState())
        titleLabel?.font = UIFont.systemFont(ofSize: font)
        sizeToFit()
    }
}
